package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;
import Models.SpclPrice;

public class SpclPricePresenter extends AbstractPresenter<SpclPrice> {
	final String SINGLEITEM = "spclPrice";
	final String MULTIITEM = "spclPrices";
	
	public ArrayList<SpclPrice> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public SpclPrice tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public SpclPrice createItemFromJSONObject(JSONObject jsonObject){
		SpclPrice item = new SpclPrice();
		try{
			item.setId(jsonObject.getInt("spid"));
			item.setCustomerID(jsonObject.getInt("custID"));
			item.setPrice(jsonObject.getDouble("price"));
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(SpclPrice item){
		try{
			JSONObject json = new JSONObject();
			json.put("spid", item.getId());
			json.put("custID", item.getCustomerID());
			json.put("price", item.getPrice());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public SpclPrice getEmptyEntity(){
		SpclPrice entity = new SpclPrice();
		return entity;
	}
}
